package com.foo.web.controller.wechat;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.foo.common.annotation.Log;
import com.foo.common.enums.BusinessType;
import com.foo.wechat.domain.WxTest;
import com.foo.wechat.service.IWxTestService;
import com.foo.common.core.controller.BaseController;
import com.foo.common.core.domain.AjaxResult;
import com.foo.common.utils.poi.ExcelUtil;
import com.foo.common.core.page.TableDataInfo;

/**
 * 测试Controller
 * 
 * @author foo
 * @date 2023-12-16
 */
@Controller
@RequestMapping("/wechat/test")
public class WxTestController extends BaseController
{
    private String prefix = "wechat/test";

    @Autowired
    private IWxTestService wxTestService;

    @RequiresPermissions("wechat:test:view")
    @GetMapping()
    public String test()
    {
        return prefix + "/test";
    }

    /**
     * 查询测试列表
     */
    @RequiresPermissions("wechat:test:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxTest wxTest)
    {
        startPage();
        List<WxTest> list = wxTestService.selectWxTestList(wxTest);
        return getDataTable(list);
    }

    /**
     * 导出测试列表
     */
    @RequiresPermissions("wechat:test:export")
    @Log(title = "测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxTest wxTest)
    {
        List<WxTest> list = wxTestService.selectWxTestList(wxTest);
        ExcelUtil<WxTest> util = new ExcelUtil<WxTest>(WxTest.class);
        return util.exportExcel(list, "test");
    }

    /**
     * 测试详情
     */
    @GetMapping("/detail/{testId}")
    public String detail(@PathVariable("testId") Long testId, ModelMap mmap)
    {
        WxTest wxTest = wxTestService.selectWxTestById(testId);
        mmap.put("wxTest", wxTest);
        return prefix + "/detail";
    }


    /**
     * 新增测试
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存测试
     */
    @RequiresPermissions("wechat:test:add")
    @Log(title = "测试", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxTest wxTest)
    {
        return toAjax(wxTestService.insertWxTest(wxTest));
    }

    /**
     * 修改测试
     */
    @GetMapping("/edit/{testId}")
    public String edit(@PathVariable("testId") Long testId, ModelMap mmap)
    {
        WxTest wxTest = wxTestService.selectWxTestById(testId);
        mmap.put("wxTest", wxTest);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试
     */
    @RequiresPermissions("wechat:test:edit")
    @Log(title = "测试", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxTest wxTest)
    {
        return toAjax(wxTestService.updateWxTest(wxTest));
    }

    /**
     * 删除测试
     */
    @RequiresPermissions("wechat:test:remove")
    @Log(title = "测试", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxTestService.deleteWxTestByIds(ids));
    }
}
